package leetcode71_80;

import org.junit.Test;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author shhjiang_001
 * @create 2020-06-21 15:02
 */
public class Solution71 {
    public String simplifyPath(String path) {
        String[] split = path.split("/");
        ArrayDeque<String> deque = new ArrayDeque<>();
        int jumpNum = 0;
        for (int i = split.length-1; i >= 0 ; i--) {
            if (".".equals(split[i]) || "".equals(split[i])) continue;
            if ("..".equals(split[i])){
                jumpNum++;
                continue;
            }
            if (jumpNum > 0){
                jumpNum--;
                continue;
            }
            deque.push(split[i]);
        }
        return "/"+String.join("/",deque);
    }

    @Test
    public void test(){
        System.out.println(simplifyPath("/a/./b/../../c/"));

        String[] arr = new String[]{"465","sdftrw","fgds"};
        List<String> strings = Arrays.asList(arr);
        String join = String.join("/", strings);
        System.out.println(join);
//        System.out.println(strings);
        int m = 12;
        int n = 5;
        System.out.println("m & n :" + (m & n));
        System.out.println("m | n :" + (m | n));
        System.out.println("m ^ n :" + (m ^ n));

    }
}
